package com.brayan.webapp.controller.realestate;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.enterprise.context.ConversationScoped;
import javax.inject.Inject;
import javax.inject.Named;

import org.apache.log4j.Logger;

import com.brayan.webapp.model.realestate.Reservation;
import com.brayan.webapp.repository.realestate.ReservationRepository;
import com.brayan.webapp.repository.usermgmt.TenantRepository;
import com.brayan.webapp.service.realestate.PriceModelBean;
import com.brayan.webapp.service.realestate.ReservationBean;

@Named
@ConversationScoped
public class ReservationsController implements Serializable {

	public ReservationsController() {
	}

	private static Logger LOGGER = Logger.getLogger(ReservationsController.class);
	private static final long serialVersionUID = -877853351738855552L;

	@Inject
	private TenantRepository tenantRepoService;
	@Inject
	ReservationRepository reservationRepoService;
	@Inject
	private PriceModelBean priceModelService;
	@Inject
	private ReservationBean reservationService;
	
	private String nameFilter;
	private boolean includePassedReservations;;

	List<Reservation> ongoingReservations = new ArrayList<Reservation>();

	/**
	 * Return Reservations by logged in user Id.
	 * @param tenantId
	 * @return
	 */
	public List<Reservation> findAllReservationsByTenantId(Long tenantId) {
		if(getNameFilter() == null || getNameFilter().isEmpty())
			return reservationRepoService.getOngoingReservations(null, isIncludePassedReservations());
		else
			return reservationRepoService.getOngoingReservationsByName(getNameFilter(), isIncludePassedReservations());
	} 
	
	public List<Reservation> findOngoingReservations() {
		if(getNameFilter() == null || getNameFilter().isEmpty())
			return reservationRepoService.getOngoingReservations(null, isIncludePassedReservations());
		else
			return reservationRepoService.getOngoingReservationsByName(getNameFilter(), isIncludePassedReservations());
	}

	public List<Reservation> findSomeOngoingReservations(Integer nRecords) {
		return reservationRepoService.getOngoingReservations(nRecords, isIncludePassedReservations());
	}

	public String getNameFilter() {
		return nameFilter;
	}

	public void setNameFilter(String nameFilter) {
		this.nameFilter = nameFilter;
	}

	public boolean isIncludePassedReservations() {
		return includePassedReservations;
	}

	public void setIncludePassedReservations(boolean includePassedReservations) {
		this.includePassedReservations = includePassedReservations;
	}

}
